package com.qf.business.student.controller;

import com.qf.data.base.r.R;
import com.qf.data.base.r.Rs;
import com.qf.feign.classes.ClsFeign;
import lombok.extern.slf4j.Slf4j;
import org.apache.skywalking.apm.toolkit.trace.Trace;
import org.apache.skywalking.apm.toolkit.trace.TraceContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.openfeign.ribbon.LoadBalancerFeignClient;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("/stu")
@Slf4j
public class StuController {

    @Autowired
    private ClsFeign clsFeign;

    @Autowired
    private LoadBalancerFeignClient client;

    @RequestMapping("/get")
    @Trace
    public R queryStu(HttpServletRequest request,Integer sid){

        String uid = request.getHeader("uid");
        System.out.println("学生登陆凭证====》"+uid);


        System.out.println("------>" + TraceContext.traceId());
        log.info("当前feign的核心调用接口：{}", client.getDelegate());
        log.info("调用了学生查询的服务：{}", sid);
        String data = (String) clsFeign.query(sid).result();
        log.info("接收到班级的响应：{}", data);
        if (sid == 1)
            System.out.println(1/0);
        return Rs.create("小明");
    }
}
